﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using University.Workshop.Model;
using University.Workshop.DataAccess;
using System.Text.RegularExpressions;
using System.Globalization;

namespace University.Workshop.Business
{
    public static class ClientManager
    {
        public static void ValidateForRegistration(string fullName, string id, string telephone, string organization, string cell, string email, string birthDate, string fax, string country, string sex)
        {
            //validacion de campos completos
            if (string.IsNullOrEmpty(fullName) || string.IsNullOrEmpty(id) || string.IsNullOrEmpty(telephone))
            {
                throw new ArgumentException("Asegurese que las campos no esten vacios");
            }
            else
            {
                ClientRegistration.AddClient(fullName, id, telephone, organization, cell, email, birthDate, fax, country, sex);
            }

            //Client client = new Client { FullName = fullName, ClientId = id, Telephone = telephone };  
            //ClientRegistration.AddClient(client);
        }

        public static void ValidateForSearching(string fullName, string id, string telephone)
        {
            //validacion de campos completos
            if (string.IsNullOrEmpty(fullName) || string.IsNullOrEmpty(id) || string.IsNullOrEmpty(telephone))
            {
                throw new ArgumentException("Asegurese que las campos no esten vacios");
            }
            else
            {
                ClientSearcher.Search(fullName, id, telephone);
            }

            Client client = new Client { FullName = fullName, ClientId = id, Telephone = telephone };

            ClientSearcher.SearchClient(client);
        }

        public static void ValidateForUpdating(string fullName, string id, string telephone, int ids)
        {
            //validacion de campos completos
            if (string.IsNullOrEmpty(fullName) || string.IsNullOrEmpty(id) || string.IsNullOrEmpty(telephone) || ids < 0)
            {
                throw new ArgumentException("Asegurese que las campos no esten vacios");
            }
            else
            {
                ClientUpdater.UpdateClient(fullName, id, telephone, ids);
            }

            //Client client = new Client { FullName = fullName, ClientId = id, Telephone = telephone };

            //ClientUpdater.UpdateClient(client, ids);
        }
        // Modificado Por Marieta
        public static string GetFullNameFromCI(string clientId)
        {
            int client;
            try
            {
                client = Convert.ToInt32(clientId, CultureInfo.InvariantCulture);
            }
            catch
            {

                throw new ArgumentException("The Format clientId is invalid ");
            }
            ClientDataAccess clientDal = new ClientDataAccess();
            clientDal.Dispose();
            return clientDal.GetFullNameFormCI(client);
        }
        // Fin Modificacion
    }
}
